
char twoLinesLCD[2][17]={" SMART LASER    ", " PROJECTOR      "};

//#define SCHEDULERMODETIME 160000 // in milliseconds (160000 correspond to 2 minutes)
//unsigned long schedulerTime;
//int schedulerMode;

#define NUM_MODES 4 //5 // up to 10 (check modeChange() method in initModes.pde)

//test time and call mode functions
void scheduler(){
//test to know if it is time to change the interaction mode
  if((millis()-schedulerTime) >  schedulerModeTime) 
  {
      // show transition graphics
      transitionStep();
      
       // prepare schedulerMode for next change of mode:
      schedulerMode=(schedulerMode+1)%NUM_MODES; // only 10 modes in this prototype (make a NUM_MODES variable, and then also be careful with the change of modes from 
      // serial input!!!)
      
      // change mode: 
      modeChange(schedulerMode);
     
      // reset timer: 
      schedulerTime = millis();
}
}

void schedulerInit(){
        // Show a graphical transition (concentric circles, max area): 
	transitionStep();
        
        schedulerModeTime=120000; // in milliseconds (REM: could vary depending on the mode: in this case, use an ARRAY: transitionTimes[10]
              
        // Initialize the next mode and the transition timer: 
        schedulerMode = 0;
        schedulerTime = millis();
        modeChange(schedulerMode);
}

void transitionStep(){
  // REM: this in fact is another BEHAVIOUR, and should be in the "behaviour" tab. TO DO...
  // In the meanwhile, I will use spot[0].
  
  // TRANSITION as CONCENTRINC CIRCLES **************************
  
  //turn off all sounds
  midiAllNoteOff();
  
  
  
  // FreeBass CC PRM init:
  // CutOff Max:
  midiControlChange(1, 107, 127);
  // Rezo Null:
  midiControlChange(1, 106, 0);
  // Envelop Modulation null:
  midiControlChange(1, 104, 0);
  // Decay max:
  midiControlChange(1, 102, 127);
  // Disto nulle:
  midiControlChange(1, 105 , 0);
      
  spotArray[0].createCircularSaccade(MAX_SACCADE_SAMPLES); 
  spotArray[0].updatePosition(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y); 
  
  // Transition is all in green: let's fix the red laser power to 0: 
  spotArray[0].PowerCorrectionMode=POWER_FIXED;
  spotArray[0].RedLaserPower=MAX_RedLaserPower; // SHOULD BE MIN, BUT THE LASER GREEN DOES NOT WORK!!!!
  IO.setRedPower_mW(MAX_RedLaserPower);

  spotArray[0].GreenLaserPower=HIGH;
  for(int l=0; l<2; l++){
    for(int i = 1500; i>=0; i-=100){
      //spotArray[0].drawMaxArea(1);
      //spotArray[0].GreenLaserPower=HIGH;
      //spotArray[0].drawMaxArea(6);
      //spotArray[0].GreenLaserPower=LOW;
      //spotArray[0].updatePosition(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
      // spotArray[0].scanTrajectory(_circularSaccade, _numSamplesCircularSaccade, paramAz, paramEl, paramAper_DA, 0)
      //spotArray[0].GreenLaserPower=HIGH;
      spotArray[0].computeNormalVector(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y, i);
      spotArray[0].computeNormalVector(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y, i);
      //spotArray[0].GreenLaserPower=LOW;
   
     // Modulation CutOff & Rezo:
      byte cutoff = (byte)(127- (127.0*i/1500.0));
      midiControlChange(1, 107, cutoff);
      byte rezo = (byte)(127- 127.0*i/1500.0);
      midiControlChange(1, 106, rezo);
      
      byte note = (byte)(48 - (24* i/1600));
   
      midiNoteOff(1, 30);
      midiNoteOn(1, 30, 100);
      }
    
    for(int i = 0; i<1500; i+=100){
      //spotArray[0].drawMaxArea(1);
     // spotArray[0].GreenLaserPower=HIGH;
      //spotArray[0].drawMaxArea(6);
     // spotArray[0].GreenLaserPower=LOW;
     // spotArray[0].updatePosition(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y);
     //spotArray[0].GreenLaserPower=HIGH;
      spotArray[0].computeNormalVector(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y, i);
      spotArray[0].computeNormalVector(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y, i);
      //spotArray[0].GreenLaserPower=LOW;
      
      byte cutoff = (byte)(127- (127.0*i/1500.0));
      midiControlChange(1, 107, cutoff);
      byte rezo = (byte)(127 - 127.0*i/1500.0);
      midiControlChange(1, 106, rezo);
      
      byte note = (byte)(48- (24* i/1600));
   
      midiNoteOff(1, 30);
      midiNoteOn(1, 30, 100);
    }
  // Circle bounce on wall >> 1 note on FB33
  midiNoteOff(0, 30);
  midiNoteOn(0, 30, 127);
  }
  spotArray[0].GreenLaserPower=LOW;
  
  lastNote=128;
  // spotArray[0].setNumSamples(18);  // not needed anymore, this will be set in the changeMode function
  spotArray[0].RedLaserPower=MAX_RedLaserPower;
  
 // ANOTHER TRANSITION GRAPHICS **************************
/*
//draw "SLP" and the max area during a short time
for(int i=0; i<50; i++){
spotArray[0].drawMaxArea(3);
spotArray[0].drawSLPLogo();
}
*/
}

